package com.t.bricks.bussiness.controller.verifycode;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.t.bricks.bussiness.model.verifycode.VerifyCodeResult;
import com.t.bricks.bussiness.server.verifycode.VerifyCodeServer;
import com.t.bricks.model.MsgEmity;

/**
 * 登录服务控制器
 */
@RestController
@RequestMapping("/verify/code")
@Api(value="验证码服务", tags={"基本业务-验证码服务操作接口"})
public class VerifyCodeController {

	@Autowired
	private VerifyCodeServer verifyCodeServer;

	/**
	 * 取图片验证码
	 * @return
	 */
	//[start]
	@ApiOperation(value="取图片验证码", response=VerifyCodeResult.class, notes="返回请求编号及base64图片")
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值|Json数据对象}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性,如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误")
	})
	//[end]
	@RequestMapping(method={RequestMethod.POST}, value="/image")
	public MsgEmity getImage() {
		return verifyCodeServer.getImage();
	}

	/**
	 * 判断提交的验证码是否符合
	 * @param sId 请求编号
	 * @param sUserTxt 提交验证的文字
	 * @return
	 */
	//[start]
	@ApiOperation(value="判断提交的验证码是否符合", notes="请求编号由取图片时获取到")
	@ApiImplicitParams({
		@ApiImplicitParam(name="sId", value="取图片时得到的请求编号", dataType="String", paramType="query", required=true),
		@ApiImplicitParam(name="sUserTxt", value="提交验证的文字", dataType="String", paramType="query", required=true)
	})
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性,如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误"),
		@ApiResponse(code=8001, message="验证码编号参数为空"),
		@ApiResponse(code=8002, message="验证码参数为空"),
		@ApiResponse(code=8003, message="未找到验证码信息,可能已经过期"),
		@ApiResponse(code=8004, message="验证码不一致"),
		@ApiResponse(code=8999, message="验证码一致")
	})
	//[end]
	@RequestMapping(method={RequestMethod.POST}, value="/check")
	public MsgEmity check(String sId, String sUserTxt) {
		return verifyCodeServer.check(sId, sUserTxt);
	}

}
